package com.br4mmie.asciistory.ui;

import com.br4mmie.asciistory.*;

/**
 * shows an animation in a textwindow
 * @author Bram Buurlage
 */
public class TextWindowWithAnimation extends TextWindow 
{
	//THE ANIMATION :D:D:D
	private Animation anim;
	
	/**
	 * constructor
	 * @param x the x location for the window
	 * @param y the y location for the window
	 * @param w the width of the window
	 * @param h the height of the window
	 * @param theMargin the margin for the text
	 * @param scrolls whether this TextWindow should scroll or be static
	 * @param animation the animation
	 */
	public TextWindowWithAnimation(int x, int y, int w, int h, int theMargin, boolean scrolls, String animation) 
	{
		super(x, y, w, h, theMargin, scrolls);
		anim = new Animation(animation, 0, 0);
		anim.setLocX(w-anim.getWidth());
		anim.setLocY(h-anim.getHeight());
		anim.play(1000);
		
		cutoff = anim.getWidth();
	}
	
	/**
	 * draws the TextWindowWithAnimation
	 */
	public void draw(CharImage target)
	{
		anim.onLoop();
		if (finished) anim.stop();
		else		  anim.resume();
		
		super.draw(target);
		anim.onDraw(image);
		
		if (showContinueMessage)
		{
			showContinueMessage = false;
			
			String continueText = "<Press "+Keybindings.INTERACT+">";
			image.drawText(image.getWidth()/2 - continueText.length()/2, image.getHeight()-2, continueText.length(), continueText);
		}
		
		superdraw(target);
	}
}
